package com.huang.router.router

import androidx.core.app.ActivityOptionsCompat
import com.alibaba.android.arouter.core.LogisticsCenter
import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.launcher.ARouter
import com.huang.router.IRouter
import com.huang.router.R
import com.huang.router.provider.AppProvider

abstract class BaseRouter : IRouter {
    /** 构建路由对象 */
    override fun build(router: String): Postcard {
        return ARouter.getInstance().build(router)
            .withOptionsCompat(
                ActivityOptionsCompat.makeCustomAnimation(
                    AppProvider.getInstance(),
                    R.anim.anim_to_left_open,
                    R.anim.anim_no
                )
            )
    }


    /** 获取路由目标对象的类 */
    override fun getDestination(router: String): Class<*> {
        val postCard = build(router)
        LogisticsCenter.completion(postCard)
        return postCard.destination
    }

}